//
//  AppDelegate.m
//  TouchNewAPI
//
//  Created by 邓杰豪 on 15/9/29.
//  Copyright © 2015年 邓杰豪. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@property(nonatomic, strong)ViewController *vc;                 
@end

@implementation AppDelegate




#pragma mark application : 独立应用程序对象 launchOptions : 启动选项 ~~字典显示应用程序启动的原因(如果有的话)。这本字典的内容可能是空的,在这种情况下,用户直接启动应用程序。可能的密钥信息在这本词典以及如何处理它们,看到启动选项键.
//当由于其它方法打开应用程序（如URL指定或者连接），通知委托启动完毕
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
//   UIApplicationShortcutItem :  创建3DTouch标签的类
    UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"斋打开" localizedTitle:@"斋打开"];
    
    UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"弹框" localizedTitle:@"弹框"];
    

    
    NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1, shortItem2, nil];
    NSLog(@"%@", shortItems);
    // UIApplication对象是应用程序的象征，一个UIApplication对象就代表一个应用程序
    // 每一个应用都有自己的UIApplication对象，而且是单例的，如果试图在程序中新建一个UIApplication对象，那么将报错提示。
    // 通过[UIApplicationsharedApplication]可以获得这个单例对象
    
    //                                  赋值
    [[UIApplication sharedApplication] setShortcutItems:shortItems];
//    NSLog(@"%@",self.window.rootViewController);
//    
//    NSLog(@"5555555555555%@",self.vc);
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


//弹出菜单，我们需要让用户点击后跳转指定页面

//这里我们会用到AppDelegate里新增加的一个方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
    if ([shortcutItem.localizedTitle  isEqual: @"弹框"]) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OPPS!" message:@"我的CTO是蓝鸥黑胖" delegate:self cancelButtonTitle:@"哦" otherButtonTitles:nil, nil];
//        [alert show];
#if 0
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"OPPS!" message:@"我的CTO是蓝鸥黑胖" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"哦" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"取消了");
            
        }];
    [alert addAction:cancel];

        
    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
        
        return;
    }
#endif
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"111" message:@"sdfsd" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"222" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        NSLog(@"取消了");
    }];
    [alert addAction:cancel];
    
    [self.window.rootViewController presentViewController:alert animated:YES completion:^{
        
        return;
    }];
    
    
    }
    
}

@end
